﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace DanhMuc
{
    class QuocTichInfo
    {
        private string _QuocTichID;

        public string QuocTichID
        {
            get { return QuocTichID; }
            set { QuocTichID = value; }
        }

        private string _TenQuocTich;

        public string TenQuocTich
        {
            get { return _TenQuocTich; }
            set { _TenQuocTich = value; }
        }

        private bool _Active;

        public bool Active
        {
            get { return _Active; }
            set { _Active = value; }
        }
    }

    class QuocTichCtr
    {
        string strCnn = DBClass_FANIT82.GetConnectString();

        public void Insert(QuocTichInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@QuocTichID", Item.QuocTichID),
                new SqlParameter("@TenQuocTich", Item.TenQuocTich == null ? (object)DBNull.Value:Item.TenQuocTich),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_QuocTich_Insert", Para);
        }

        public void Update(QuocTichInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@QuocTichID", Item.QuocTichID),
                new SqlParameter("@TenQuocTich", Item.TenQuocTich == null ? (object)DBNull.Value:Item.TenQuocTich),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_QuocTich_Update", Para);
        }

        public void Delete(string strQuocTichID)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@QuocTichID", strQuocTichID),
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_QuocTich_Delete", Para);
        }

        public DataTable GetList()
        {
            DataSet Ds = SqlHelper.ExecuteDataset(strCnn, CommandType.StoredProcedure, "D_QuocTich_GetList");
            return Ds.Tables[0];
        }

        public QuocTichInfo GetByID(string strQuocTichID)
        {
            SqlDataReader dtr = SqlHelper.ExecuteReader(strCnn, CommandType.StoredProcedure, "D_QuocTich_Get", new SqlParameter("QuocTichID", strQuocTichID));
            QuocTichInfo ObjQuocTich = null;
            while (dtr.Read())
            {
                ObjQuocTich = new QuocTichInfo();
                ObjQuocTich.QuocTichID = dtr["QuocTichID"].ToString();
                ObjQuocTich.TenQuocTich = dtr["TenQuocTich"].ToString();
                ObjQuocTich.Active = (bool)dtr["Active"];
            }
            return ObjQuocTich;
        }
    }
}
